package dto

import (
	"go-admin/app/admin/models"
	"go-admin/common/dto"
	common "go-admin/common/models"
)

type EnvironmentGetPageReq struct {
	dto.Pagination `search:"-"`
	Name           string `form:"name"  search:"type:exact;column:name;table:environment" comment:"环境名称"`
	Remark         string `form:"remark"  search:"type:exact;column:remark;table:environment" comment:"备注"`
	EnvironmentOrder
}

type EnvironmentOrder struct {
	Id        string `form:"idOrder"  search:"type:order;column:id;table:environment"`
	Name      string `form:"nameOrder"  search:"type:order;column:name;table:environment"`
	Remark    string `form:"remarkOrder"  search:"type:order;column:remark;table:environment"`
	CreatedAt string `form:"createdAtOrder"  search:"type:order;column:created_at;table:environment"`
	UpdatedAt string `form:"updatedAtOrder"  search:"type:order;column:updated_at;table:environment"`
	DeletedAt string `form:"deletedAtOrder"  search:"type:order;column:deleted_at;table:environment"`
	CreateBy  string `form:"createByOrder"  search:"type:order;column:create_by;table:environment"`
	UpdateBy  string `form:"updateByOrder"  search:"type:order;column:update_by;table:environment"`
}

func (m *EnvironmentGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type EnvironmentInsertReq struct {
	Id           int    `json:"-" comment:"编码"` // 编码
	Name         string `json:"name" gorm:"type:varchar(128);comment:环境名称"`
	Code         string `json:"code" gorm:"type:varchar(128);comment:环境标识"`
	CodeBranch   string `json:"codeBranch" gorm:"type:varchar(128);comment:代码分支"`
	Credential   string `json:"credential" gorm:"type:varchar(128);comment:gitlab凭证"`
	Namespace    string `json:"namespace" gorm:"type:varchar(128);comment:命名空间"`
	ClusterId    int    `json:"clusterId" gorm:"type:int;comment:集群id"`
	JenkinsId    int    `json:"jenkinsId" gorm:"type:int;comment:jenkins id"`
	ImageUrl     string `json:"imageUrl" gorm:"type:varchar(128);comment:镜像仓库地址"`
	ImageProject string `json:"imageProject" gorm:"type:varchar(128);comment:镜像仓库项目"`
	Notify       string `json:"notify" gorm:"type:varchar(128);comment:飞书通知"`
	Remark       string `json:"remark" gorm:"type:varchar(255);comment:备注"`
	common.ControlBy
}

func (s *EnvironmentInsertReq) Generate(model *models.Environment) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.Name = s.Name
	model.Code = s.Code
	model.Credential = s.Credential
	model.Namespace = s.Namespace
	model.CodeBranch = s.CodeBranch
	model.ClusterId = s.ClusterId
	model.JenkinsId = s.JenkinsId
	model.ImageUrl = s.ImageUrl
	model.ImageProject = s.ImageProject
	model.Remark = s.Remark
	model.Notify = s.Notify
	model.CreateBy = s.CreateBy // 添加这而，需要记录是被谁创建的
}

func (s *EnvironmentInsertReq) GetId() interface{} {
	return s.Id
}

type EnvironmentUpdateReq struct {
	Id           int    `uri:"id" comment:"编码"` // 编码
	Name         string `json:"name" gorm:"type:varchar(128);comment:环境名称"`
	Code         string `json:"code" gorm:"type:varchar(128);comment:环境标识"`
	CodeBranch   string `json:"codeBranch" gorm:"type:varchar(128);comment:代码分支"`
	Credential   string `json:"credential" gorm:"type:varchar(128);comment:gitlab凭证"`
	Namespace    string `json:"namespace" gorm:"type:varchar(128);comment:命名空间"`
	ClusterId    int    `json:"clusterId" gorm:"type:int;comment:集群id"`
	JenkinsId    int    `json:"jenkinsId" gorm:"type:int;comment:jenkins id"`
	ImageUrl     string `json:"imageUrl" gorm:"type:varchar(128);comment:镜像仓库地址"`
	ImageProject string `json:"imageProject" gorm:"type:varchar(128);comment:镜像仓库项目"`
	Notify       string `json:"notify" gorm:"type:varchar(128);comment:飞书通知"`
	Remark       string `json:"remark" gorm:"type:varchar(255);comment:备注"`
	common.ControlBy
}

func (s *EnvironmentUpdateReq) Generate(model *models.Environment) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.Name = s.Name
	model.Code = s.Code
	model.Credential = s.Credential
	model.Namespace = s.Namespace
	model.CodeBranch = s.CodeBranch
	model.ClusterId = s.ClusterId
	model.JenkinsId = s.JenkinsId
	model.ImageUrl = s.ImageUrl
	model.ImageProject = s.ImageProject
	model.Remark = s.Remark
	model.Notify = s.Notify
	model.UpdateBy = s.UpdateBy // 添加这而，需要记录是被谁更新的
}

func (s *EnvironmentUpdateReq) GetId() interface{} {
	return s.Id
}

// EnvironmentGetReq 功能获取请求参数
type EnvironmentGetReq struct {
	Id int `uri:"id"`
}

func (s *EnvironmentGetReq) GetId() interface{} {
	return s.Id
}

// EnvironmentDeleteReq 功能删除请求参数
type EnvironmentDeleteReq struct {
	Ids []int `json:"ids"`
}

func (s *EnvironmentDeleteReq) GetId() interface{} {
	return s.Ids
}
